<!--
 * @Author: your name
 * @Date: 2021-01-20 15:02:11
 * @LastEditTime: 2021-01-26 19:30:31
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wms2\src\views\components\warehouseSelect.vue
-->
<template>
  <el-select v-model="value" filterable placeholder="请选择" @change="changeValue($event)" clearable style="width:100%">
    <el-option
      v-for="item in warehouses"
      :key="item.code"
      :label="item.name"
      :value="item.code"
    />
  </el-select>
</template>
<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      value: '',
      warehouses: [],
      callbackMethod: '',
      warehouseName: '',
      shipmentCode: '',
    }
  },
  created() {
    this.findList()
  },
  methods: {
    init(shipmentCode = '', warehouseName = ''){
      this.warehouseName = warehouseName;
      this.shipmentCode = shipmentCode;
    },
    findList() {
      return request({
        url: '/wms/warehouse/business/warehouse',
        method: 'get',
      }).then(response => {
        this.warehouses = response.data
        if(this.warehouses.length === 1){
          this.$emit("setWarehouseCode", this.warehouses[0].code)
          this.value = this.warehouses[0].code
        }
      })
    },

    changeValue(e) {
      this.$emit("setWarehouseCode", e)
    },

    setSelectValue(shipmentCode, value) {
      this.findList().then( _ => {
        this.value = value
      })
      
      // this.init(shipmentCode).then(()=>{
      //   if(value!=''){
      //     this.warehouses.forEach(i =>{
      //       if(i.code == value){
      //         this.value = i.name
      //       }
      //       if(i.name == value){
      //         this.value = value
      //       }
      //     })
      //   }else{
      //     this.value = value
      //   }
      // })
    },
  }
}
</script>
